{% extends 'base.html' %}


{% block content %}
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
        <legend id="titleLeg"> 项目版信息管理</legend>
    </fieldset>
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <div>
        <a href="{{ url_for('manage.manageadd') }}">
            <button type="button" class="layui-btn layui-btn-primary" id="butn">添加</button>
        </a>
    </div>

{% endblock %}

{% block script %}
    {{ super() }}
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">查看 | 编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#test'
                , url: '{{ url_for('manage.gpApi') }}'
                , title: '项目管理'
                , width: 800
                , cols: [[
                    {field: 'id', width: 80, title: 'ID', sort: true}
                    , {field: 'name', width: 280, title: '项目名称', sort: true}
                    , {field: 'position', width: 138, title: '项目位置'}
                    , {field: 'ctime', width: 135, title: '部署时间', sort: true}
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
                ]]
                , page: true
            });
            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('确定删除?', {icon: 3, title: '警告提示'}, function (index) {
                        layer.confirm('删除将不可恢复', function (index) {
                            $.ajax({
                                url: '/manage/gpdApi/' + data.id,
                                type: "delete",
                                async: false,
                                success: function (data) {
                                    if (data.code == 10000){
                                        obj.del();
                                        layer.msg('删除成功', {"icon": 1})
                                    } else {
                                        layer.msg("删除失败", {"icon": 5})
                                    }
                                }
                            });
                            layer.close(index);
                        });
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    window.open('/manage/manageEdit/' + data.id , '_self');
                    {#layer.msg('点击了编辑事件', {icon: 1})#}
                }
            });
        });
    </script>

{% endblock %}